package org.bbelovic.devel.exercises.number;

public class NumberUtilities {

    public static int gcd(int n, int m) {
        return gcdEuclidRecursive(n, m);
    }

    private static int gcdEuclidRecursive(int n, int m) {
        if (n == 0) return m;
        if (m == 0) return n;
        if (n % m == 0) return m;
        else return gcd(m,n % m);
    }

    private static int gcdEuclid(int n, int m) {
        if (n == 0) return m;
        if (m == 0) return n;
        while (n % m != 0) {
            int newN = n % m;
            n = m;
            m = newN;
        }
        return m;
    }

    private static int gcdDummy(final int n, final int m) {
        final int min = n <= m ? n : m;
        final int max = n > m ? n : m;
        int gcd = max;
        for (int i = 1; i <= min; i++) {
            if (n % i == 0 && m % i == 0) {
                gcd = i;
            }
        }
        return gcd;
    }
}
